float3 LightPosition;

float4 DiffuseColor;
float3 EmissiveColor;	
float3 AmbientColor;			

float4 Booleans01;			

float ToonThresholds[2] = { 0.8, 0.4 };
float ToonBrightnessLevels[3] = { 1.3, 0.9, 0.5 };	

// Structs
struct VS_OUTPUT
{
    float4 position				: POSITION;
	float2 textureCoords		: TEXCOORD0;
	float3 positionW			: TEXCOORD1;
	float3 normalW				: TEXCOORD2;
};

// Samplers
sampler2D DiffuseSampler		: register(s0);

// Shaders
float4 main(VS_OUTPUT In) : COLOR
{
	float3 baseColor = 1;
	float3 normalW = normalize(In.normalW);

	if (Booleans01.x == 1.0f)
		baseColor = tex2D(DiffuseSampler, In.textureCoords).rgb;

	// Diffuse Lighting
	float3 lightDirectionW = normalize(LightPosition - In.positionW);
	float ndl = max(0, dot(normalW, lightDirectionW));

	// Tooning
	if (ndl > ToonThresholds[0])
        ndl = ToonBrightnessLevels[0];
    else if (ndl > ToonThresholds[1])
        ndl = ToonBrightnessLevels[1];
    else
        ndl = ToonBrightnessLevels[2];

	float3 diffuse = DiffuseColor.rgb * ndl;
	
	// Final
	return float4(saturate(saturate(diffuse +  EmissiveColor) + AmbientColor) * baseColor, DiffuseColor.a);
}